const path = require('path')
const {sep} = path
const glob = require('glob')
// 匹配  当前目录及其子目录下素所有的js

module.exports=(app)=>{
  const extendPath = path.resolve(app.businessPath,`.${sep}extend`)
  const filelist = glob.sync(path.resolve(extendPath,`.${sep}**${sep}**.js`))
  filelist.forEach(file => {
      const name = path.resolve(file)
      // 截取字符串 controller/ 到 .js
      name = name.substring(
        name.lastIndexOf(`controller${sep}`)+`controller${sep}`.length,
        name.lastIndexOf('.')
      )
      name = name.replace(/[_-][a-z]/gi,(s)=>substring(1).toUpperCase());
      for(const key in app){
        if(key===name){
          return 
        }
      }
      app[name] = require(path.resolve(file))(app)
     
      
  });
}

